package wwk.com.android_meilishuo.ui.secondfloor;

import android.content.Context;
import android.os.Handler;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.wwk.core.views.RevealTextView;

import java.util.List;

import wwk.com.android_meilishuo.R;

/**
 * Created by Administrator on 2016/12/28.
 */

public class MyVerticalViewPagerAdapter extends PagerAdapter implements View.OnClickListener {
    private List<DataBean> dataBeanList = null;
    private Context mContext = null;
    //声明布局填充器
    private LayoutInflater mLayoutInflater = null;
    private ImageView imageView_SF, imageView_mls;
    private TextView textView_time, textView_week, textView_name;
    //闪现的textview
    private RevealTextView textView_content;
    private ImageView imageView_share, imageView_comment, imageView_back;

    public MyVerticalViewPagerAdapter(List<DataBean> _dataBeanList, Context _mContext) {
        this.dataBeanList = _dataBeanList;
        this.mContext = _mContext;
        mLayoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override//获取数据的大小
    public int getCount() {
        return dataBeanList.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, final int position) {
        View view = mLayoutInflater.inflate(R.layout.item_second_foor, null);
        imageView_share = (ImageView) view.findViewById(R.id.imageView_share);
        imageView_comment = (ImageView) view.findViewById(R.id.imageView_comment);
        imageView_back = (ImageView) view.findViewById(R.id.imageView_back);
        imageView_share.setOnClickListener(this);
        imageView_comment.setOnClickListener(this);
        imageView_back.setOnClickListener(this);

        imageView_SF = (ImageView) view.findViewById(R.id.imageView_SF);
        imageView_mls = (ImageView) view.findViewById(R.id.imageView_mls);
        textView_time = (TextView) view.findViewById(R.id.textView_time);
        textView_week = (TextView) view.findViewById(R.id.textView_week);
        textView_content = (RevealTextView) view.findViewById(R.id.textView_content);
        textView_name = (TextView) view.findViewById(R.id.textView_name);
        Glide.with(mContext).load(dataBeanList.get(position).getImg_o()).into(imageView_SF);
        Glide.with(mContext).load(dataBeanList.get(position).getWater_img_ios()).into(imageView_mls);
        textView_time.setText(dataBeanList.get(position).getDate());
        textView_week.setText(dataBeanList.get(position).getWeek());
        textView_content.setAnimatedText(dataBeanList.get(position).getDescription());
       /* new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                textView_content.setAnimatedText(dataBeanList.get(position).getDescription());
            }
        }, 1000);*/
        //textView_content.setText(dataBeanList.get(position).getDescription());
        // textView_content.startAnimation(AnimationUtils.loadAnimation(mContext, R.anim.alpha_second));
        textView_name.setText(dataBeanList.get(position).getLabel());
        container.addView(view);
        return view;
    }


    @Override//清理图片item
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.imageView_share:

                break;
            case R.id.imageView_comment:

                break;
            case R.id.imageView_back:
                ((SecondFloorActivity) mContext).finish();
                break;
        }
    }
}
